package com.example.demo.interview;

public class MyClone {

    public static void main(String[] args) throws CloneNotSupportedException {
        Teacher t = new Teacher("张三",29);
        Teacher t1 = (Teacher) t.clone();
        System.out.println(t);
        System.out.println(t1);
        t.setAge(30);
        System.out.println("--------------------");
        System.out.println(t);
        System.out.println(t1);
    }

}

class Teacher implements Cloneable{
    private String name;

    private int age;


    public Teacher(String name, int age) {
        this.name = name;
        this.age = age;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public Object clone() throws CloneNotSupportedException {
        Object object = super.clone();
        return object;
    }
}